<?php

function getPG($query){
	$dbconn = pg_connect("host=localhost port=5432 dbname=edoc user=mooz password=moo2520")
    	or die('Could not connect: ' . pg_last_error());

	$result = pg_query($query) or die('Query failed: ' . pg_last_error());
	$ret = array();
	$index = 0;

	while($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
		$ret[$index] = $line;
		$index = $index+1;
	}

	pg_free_result($result);
	pg_close($dbconn);
	
	return $ret;
}

function updatePG($query){
	$dbconn = pg_connect("host=localhost port=5432 dbname=edoc user=mooz password=moo2520")
		or die('Could not connect: ' . pg_last_error());
		
	$result = pg_exec($dbconn,$query);

	pg_close($dbconn);
	
	return $result;
}

$edoc_comment = getPG("select comment,edoc_id from edoc order by edoc_id");
foreach($edoc_comment as $record)
{
	echo " ".$record["edoc_id"]." ";
	updatePG("update edoc_recieve set comment='".$record["comment"]."' where edoc_id=".$record["edoc_id"]."");
}



?>
